package com.xcalendar.servlets;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.appengine.api.datastore.KeyFactory;
import com.xcalendar.constant.XConstants;
import com.xcalendar.database.table.Event;
import com.xcalendar.database.table.User;
import com.xcalendar.management.EventManager;
import com.xcalendar.managementImpl.EventManagerImpl;

@SuppressWarnings("serial")
public class DragEventController extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
	//	HttpSession session = request.getSession();
	//	User user = (User)session.getAttribute(XConstants.SESSION_USER);
		EventManager eventManager = new EventManagerImpl();
		
		String eventId = request.getParameter("eventIdDrop");
		String eventTitle = request.getParameter("eventTitleDrop");
		String description = request.getParameter("eventDescriptionDrop");
		String start = request.getParameter("eventStartDrop");
		String end = request.getParameter("eventEndDrop");
		Date dStart = new Date(start);
		Date dEnd = new Date(end);
		dStart.setHours(dStart.getHours()+1);
		dEnd.setHours(dEnd.getHours()+1);
		Event event = new Event();
		event.setKey(KeyFactory.stringToKey(eventId));
		event.setTitle(eventTitle);
		event.setDescription(description);
		event.setStartTime(dStart);
		event.setEndTime(dEnd);
		eventManager.updateEvent(event);
		resp.setContentType("text/plain");
		resp.getWriter().println("dropSuccessfully");
	
		
	}
}
